package com.jia.train.seat.controller;

import com.jia.train.global.page.PageResponse;
import com.jia.train.global.response.BaseResponse;
import com.jia.train.seat.request.GeneratorSeatRequest;
import com.jia.train.seat.request.TrainSeatQueryRequest;
import com.jia.train.seat.request.TrainSeatSaveRequest;
import com.jia.train.seat.response.TrainSeatQueryResponse;
import com.jia.train.seat.response.TrainSeatSaveResponse;
import com.jia.train.seat.service.TrainSeatService;
import jakarta.annotation.Resource;
import jakarta.validation.Valid;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/train")
public class TrainSeatController {

    @Resource
    private TrainSeatService trainSeatService;

    @PostMapping("/insert")
    public BaseResponse<TrainSeatSaveResponse> insertTrainSeat(@Valid @RequestBody TrainSeatSaveRequest request) {
        TrainSeatSaveResponse response = trainSeatService.insert(request);
        return new BaseResponse<>(response);
    }

    @GetMapping("/query")
    public BaseResponse<PageResponse<TrainSeatQueryResponse>> query(@Valid TrainSeatQueryRequest request) {
        PageResponse<TrainSeatQueryResponse> responseList = trainSeatService.selectPage(request);
        return new BaseResponse<>(responseList);
    }

    @DeleteMapping("/delete/{id}")
    public BaseResponse<String> delete(@PathVariable Long id) {
        trainSeatService.deleteTrainSeat(id);
        return new BaseResponse<>("success");
    }

    @PostMapping("/generator")
    public BaseResponse<Integer> generatorSeat(@Valid @RequestBody GeneratorSeatRequest request) {
        trainSeatService.generatorSeat(request);
        return new BaseResponse<>(1000);
    }

}
